    var geocoder;
    var cityName;

    function initialize() {
        geocoder = new google.maps.Geocoder();
    }

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
    }

    //Get latitude and longitude;
    function successFunction(position) {
        var lat = position.coords.latitude;
        var lng = position.coords.longitude;
        codeLatLng(lat, lng)
    }

    function errorFunction(error) {
        alert("Error");
    }

    function codeLatLng(lat, lng) {

        var latlng = new google.maps.LatLng(lat, lng);
        geocoder.geocode({
            'latLng' : latlng
        }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                console.log(results)
                if (results[1]) {
                    //formatted address
                    var city = results[3].address_components[0].short_name + ", "
                            + results[3].address_components[3].short_name;
                    cityNameCallback(city);

                } else {
                    console.log("No results found");
                }
            } else {
                console.log("Geocoder failed due to: " + status);
            }
        });
    }

    function cityNameCallback(cityName) {
        document.getElementById("city").value = cityName;
    }

function sendRequest()
{
    postData = {
        action: 'Add',
        user: $('#user').val(),
        story: $('#story').val(),
        city: $('#city').val()
	};
    
    $.getJSON("/rpc",
	postData, function(rsp) {
		console.log(rsp)
		

		$('#result').val(rsp.output);
        
    })
}

$('#submitButton').live('click', function() {
    sendRequest();
    return false;
})
